#!/bin/bash
#
# Copyright (c) 2008 Nokia Corporation.
# All rights reserved.
#
# Licensed under GPL version 2
#
# texi2html wrapper: Provides compatibily with a very old
# version of texi2html, which places all output files to
# the current directory. This used to be included in the
# old scratchbox 1 devkits, but now when they have updated
# it, many packages have been fixed and this is not so
# useful anymore.
#
# Enable the old texi2html functionality by setting
# SBOX_WRAPPER_TEXI2HTML_EMULATE_OLD_VERSION:
# Once enabled, this checks that the output file(s) will be placed to
# the current directory. Old version of texi2html did that by default,
# but newer versions create a subdirectory for the output files.
# Unfortunately many packages depend on the old way (because the old tool
# is the one that was used with scratchbox 1)
#
# Author: Lauri T. Aarnio

args="$*"
prog="$0"
progbase=`basename $0`

function error_not_inside_sb2()
{
	echo "SB2: $progbase: This wrapper can only be used from inside"
	echo "the scratchbox 2'ed environment"
	exit 1
}

if [ -z "$SBOX_SESSION_DIR" ]
then
	error_not_inside_sb2
fi

. $SBOX_SESSION_DIR/sb2-session.conf

real_tool=$sbox_tools/usr/bin/texi2html

if [ -z "$args" ]
then
	# No arguments
	exec $real_tool
fi

if [ -z "$SBOX_WRAPPER_TEXI2HTML_EMULATE_OLD_VERSION" ]
then
	# texi2html emulation has not been requested,
	# just go and do it..
	exec $real_tool $args
fi

# check options
for i in $args
do
	case "$i" in
	--output*)	# Output already assigned, don't change it
			exec $real_tool $args
			;;
	-monolithic)	# create a single file to current directory:
			# no need to modify output directory
			exec $real_tool $args
			;;
	esac
done

# No --output or -monolithic; use --output=. to force the output files
# to current directory
exec $real_tool --output=. $args

